/*
@author: stanfor
@date: 2022/8/3 10:00
@Version: 1.0
@last Modifined time : 2022/8/3 10:00
*/

import React from 'react';
import Layout from '@/layout';
import Login from '@V/login';
import { getCookie } from '@U/config';
import { Redirect, Route, Switch } from 'react-router-dom';

const RoutingLayout = () => {
  // 当 token 权限存在时，
  return (
    <>
      <Switch>
        <Route
          path="/login"
          render={() => {
            const { token } = getCookie('userInfo') ?? {};
            return token ? <Redirect exact to="/dashboard"/> : <Login/>;
          }}
        />
        { getCookie('userInfo')?.token ? <Layout/> : <Redirect exact to="/login"/> }
      </Switch>
    </>
  )
}

export default RoutingLayout;
